package hoyo.zqy.basic.controller;

import hoyo.zqy.basic.exception.BusinessException;
import hoyo.zqy.basic.service.IVerifyCodeService;
import hoyo.zqy.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    @GetMapping("/image/{key}")
    public  String getImageCode(@PathVariable("key") String key){
        return  verifyCodeService.getImageCody(key);
    }

    /**
     * 手机验证码发送
     * @param map
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult getsmsCode(@RequestBody Map<String,String> map){
        try {
            verifyCodeService.getsmsCode(map);
            return AjaxResult.me();
        } catch (BusinessException e) {
            return new  AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"快跑，本页面要崩溃了");
        }
    }
    /**
     * 微信验证码发送
     * @param map
     * @return
     */
    @PostMapping("/binderSmsCode")
    public AjaxResult binderSmsCode(@RequestBody Map<String,String> map){
        try {
            verifyCodeService.binderSmsCode(map);
            return AjaxResult.me();
        } catch (BusinessException e) {
            return new  AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"快跑，本页面要崩溃了");
        }
    }
}
